home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Drvr.c
-
- Contains: This is the Unit Table dcmd.
-
- Written by: JM3 = Jim Murphy
- DAL = Dave Lyons
- sad = Scott Douglass
-
- Copyright: ⌐ 1988,1993-1998 by Apple Computer, Inc., All Rights Reserved.
-
- File Ownership:
-
- DRI: Jim Murphy
-
- Other Contact: Dave Lyons
-
- Technology: MacsBug
-
- Writers:
-
- (JM3) Jim Murphy
- (fau) Fernando Urbina
- (DAL) Dave Lyons
-
- Change History (most recent first):
-
- <10> 8/3/98 JM3 Use lomem accessors so we can nuke the include of SysEqu.h.
- <9> 7/14/98 DAL Cosmetic.
- <8> 5/27/98 fau Version 3.0.2: Changed the storage field to display the
- "storage" for 68K drivers and the driver version for native
- drivers (in hex). Updated the help string accordingly.
- <7> 6/17/97 DAL -b = busy only. Version 3.0.1.
- <6> 25-Jan-96 JM3 Updated the sample build commands to be current.
- <5> 10/27/95 DAL Draw "-nil-" instead of empty-string for nil DRVR handles
- (merged in from Scott Douglass' source).
- <4> 10-Dec-94 JM3 Updated for new format 3 dcmd requirements.
- <3> 3/14/94 DAL Re-layed-out the columns: removed Window and made room for
- everything to be nice on 13" monitors. Made the "that's strange"
- message not show up for dRef = 0xFFFE (.Sony for HD-20). Now
- Hoon is happy.
- <2> 9/14/93 DAL made the driver name column wider
-
- Modification history:
- 7Dec88 sad show driver version
- 29Nov88 sad revised for new dcmd names
- 13Oct88 sad written from file.c
-
- The following MPW commands will build the dcmd and copy it to the "Debugger Prefs" file
- in the System folder. The dcmd's name in MacsBug will be the name of the file built by
- the Linker.
-
- C Drvr.c
- Link -o Drvr -sg Main=STDCLIB,STDIO,SANELIB dcmdGlue.a.o Put.c.o Drvr.c.o" ╢
- "{Libraries}Runtime.o"
- BuildDcmd Drvr 193 -format3
- Echo 'include "Drvr";' | Rez -a -o "{SystemFolder}Debugger Prefs"
-
- */
-
- #include <MacTypes.h>
- #include <MacMemory.h>
- #include <Devices.h>
- #include <DriverFamilyMatching.h>
- #include <LowMem.h>
-
- #include "dcmd.h"
- #include "put.h"
-
-
- typedef struct DRVR
- {
- short drvrFlags;
- short drvrDelay;
- short drvrEMask;
- short drvrMenu;
- short drvrOpen;
- short drvrPrime;
- short drvrCtl;
- short drvrStatus;
- short drvrClose;
- Str255 drvrName;
- } DRVR;
-
-
- static void DrawHdr()
- {
- // 0 1 2 3 4 5 6 7 8 9
- // 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
- dcmdDrawLine("\pdRef dNum Driver Flg Ver qHead Stor/Ver Dely Drvr at DCE at");
- }
-
- #define kColumnNameEnd 37
- #define kColumnVersionEnd 46
- #define kColumnQHeadEnd 54
- #define kColumnStorageEnd 64
- #define kColumnDriverAtEnd 78
- #define kColumnDCEAtEnd 85
-
-
- static void DrawDCE(short dref, AuxDCE* dcep)
- {
- DRVR* drvrp;
-
- PutUHexWord(dref);
- PutSpace();
- PutUHexWord(~dref);
- PutSpace();
- if (dcep->dCtlFlags & 0x40)
- {
- if (dcep->dCtlDriver)
- {
- drvrp = * (DRVR **) dcep->dCtlDriver;
- if (drvrp)
- PutPStrTruncTo(drvrp->drvrName, kColumnNameEnd);
- else
- PutPStrTruncTo("\p-purged-", kColumnNameEnd);
- }
- else
- {
- PutPStrTruncTo("\p-nil-", kColumnNameEnd);
- };
- }
- else
- {
- if (dcep->dCtlDriver)
- {
- drvrp = (DRVR*)dcep->dCtlDriver;
- PutPStrTruncTo(drvrp->drvrName, kColumnNameEnd);
- }
- else
- {
- PutPStrTruncTo("\p-nil-", kColumnNameEnd);
- };
- };
- PutSpace();
- PutChar((dcep->dCtlFlags & 0x80) ? 'B' : 'b');
- PutChar((dcep->dCtlFlags & 0x40) ? 'H' : 'P');
- PutChar((dcep->dCtlFlags & 0x20) ? 'O' : 'C');
- PutSpace();
- PutUDecTo((unsigned char) dcep->dCtlQHdr.qFlags,kColumnVersionEnd); // version
- PutSpace();
- PutUHexZTo((unsigned long) dcep->dCtlQHdr.qHead,8,kColumnQHeadEnd); // qHead
- PutSpace();
-
- if ( dcep->dCtlFlags & (1<<3) ) // Is_Native
- {
- DriverDescriptionPtr descPtr = (DriverDescriptionPtr) dcep->dCtlOwner;
-
- PutUHexZTo( descPtr->driverType.version.majorRev, 2, kColumnStorageEnd-6);
- PutChar('.');
- PutUHexZTo( descPtr->driverType.version.minorAndBugRev, 2, kColumnStorageEnd-3);
-
- switch (descPtr->driverType.version.stage)
- {
- case 0x40:
- PutChar('a');
- break;
- case 0x60:
- PutChar('b');
- break;
- case 0x80:
- PutChar('f');
- break;
- case 0x20:
- PutChar('d');
- break;
- default:
- PutChar('?');
- break;
- }
-
- PutUHexZTo( descPtr->driverType.version.nonRelRev, 2, kColumnStorageEnd);
-
- }
- else
- {
- PutUHexZTo((unsigned long) dcep->dCtlStorage,8,kColumnStorageEnd); // Storage
- }
- PutSpace();
- PutUHexWord((unsigned long) dcep->dCtlDelay);
- PutSpace();
- PutUHexZTo((unsigned long) drvrp,8,kColumnDriverAtEnd);
- PutSpace();
- PutUHexZTo((unsigned long) dcep,8,kColumnDCEAtEnd);
- PutLine();
-
- // For drvr FFFE (.Sony for the HD20, pre-SCSI), it's okay that
- // the dCtlRefNum is $FFFB (don't whine about it)
-
- if ( (dref != dcep->dCtlRefNum) && ( ((unsigned short) dref) != (unsigned short) 0xFFFE) )
- {
- PutPStr("\p that is strange: dCtlRefNum = ");
- PutUHexWord(dcep->dCtlRefNum);
- PutLine();
- }
- } // DrawDCE
-
-
- pascal void DoDrvrCommand(dcmdBlock* paramPtr)
- {
- Boolean doOne = false;
- Boolean busyOnly = false;
- long dref;
- short NumDCEs;
-
- dcmdSwapWorlds();
-
- dcmdDrawLine("\pDisplaying Driver Control Entries");
-
- // Get low-memory values after dcmdSwapWorlds().
-
- NumDCEs = LMGetUnitTableEntryCount();
-
- if ( dcmdPeekAtNextChar() == '-' )
- {
- short oldPos = dcmdGetPosition();
- short ch;
-
- dcmdGetNextChar(); // eat the "-"
-
- ch = dcmdGetNextChar();
-
- if ( ch == 'b' || ch == 'B' )
- busyOnly = true;
- else
- dcmdSetPosition( oldPos );
- }
-
- if ( !busyOnly )
- (void) dcmdGetNextExpression(&dref, &doOne);
-
- if (doOne) // info on one specific driver
- {
- short dnum;
-
- dref = (short) dref;
-
- if (dref < 0)
- {
- dnum = ~dref;
- }
- else
- {
- dnum = dref;
- dref = ~dref;
- }
-
- if (dnum > NumDCEs)
- {
- PutPStr("\pBad refnum ");
- PutUHexWord(dref);
- PutSpace();
- PutUHexWord(~dref);
- PutLine();
- }
- else
- {
- AuxDCE** dceh = ((AuxDCE***)LMGetUTableBase())[dnum];
- if (dceh)
- {
- DrawHdr();
- DrawDCE(dref,*dceh);
- }
- else
- {
- PutPStr("\pDriver ");
- PutUHexWord(dref);
- PutSpace();
- PutUHexWord(~dref);
- PutPStr("\p is not installed");
- PutLine();
- }
- }
- }
- else // no driver number specified on command line
- {
- short DCEsUsed = 0;
- short dnum;
- AuxDCE*** dcehp;
- Boolean foundOne = false;
- for(dnum = 0, dcehp = (AuxDCE***) LMGetUTableBase(); dnum < NumDCEs; dnum++, dcehp++)
- {
- if (*dcehp)
- {
- if (busyOnly && (**dcehp)->dCtlQHdr.qHead == 0)
- continue;
-
- DCEsUsed++;
- if (!foundOne)
- {
- DrawHdr();
- foundOne = true;
- }
- DrawDCE(~dnum,**dcehp);
- }
-
- if (paramPtr->aborted)
- break;
- }
-
- if ( !paramPtr->aborted )
- {
- if ( busyOnly )
- {
- if ( !foundOne )
- {
- PutPStr("\pNo drivers are busy.");
- PutLine();
- }
- }
- else
- {
- PutUDec(NumDCEs);
- PutPStr("\p Unit Table entries, ");
- PutUDec(DCEsUsed);
- PutPStr("\p in use, ");
- PutUDec(NumDCEs - DCEsUsed);
- PutPStr("\p free");
- PutLine();
- }
- }
- }
-
- dcmdSwapWorlds();
- } // DoDrvrCommand
-
-
- pascal void CommandEntry(dcmdBlock* paramPtr)
- {
-
- static const Str255 usageStr = "\p[refNum|num] | -b";
-
- switch (paramPtr->request)
- {
- case dcmdInit:
- break;
-
- case dcmdHelp:
- dcmdDrawLine("\pDisplays driver information for the given refNum or all installed");
- dcmdDrawLine("\pdrivers. Flags are B/b=Busy, H/P=Handle/Ptr, O/C=Open/Closed.");
- dcmdDrawLine("\pStor/Ver field shows the storage for 68k drivers and the version");
- dcmdDrawLine("\pfor native drivers.");
- dcmdDrawLine("\p drvr -b shows only the drivers that are busy.");
- break;
-
- case dcmdGetInfo:
- * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03028000; // version 3.0.2 final
- BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
- break;
-
- case dcmdDoIt:
- DoDrvrCommand(paramPtr);
- break;
-
- // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
-
- default:
- break;
- }
- } // CommandEntry
-